from owlready2 import *

onto = get_ontology('http://test.org/onto/')
namespace = onto.get_namespace('http://test.org/onto/pharmaco')

def create_class_in_spacific_namespace():
    print('1. create_class_in_spacific_namespace')
    class Drug(Thing):
        namespace = namespace
    print('\tDrug.namespace:', Drug.namespace)
    # 隐含命名空间来自继承对象
    class Drug2(Drug): pass
    print('\tDrug2.namespace:', Drug2.namespace)

def modifying_class_defined_another_ontology():
    print('2. modifying_class_defined_another_ontology')
    onto1 = get_ontology('http://test1.org/my_first_ontology.owl')
    onto2 = get_ontology('http://test2.org/my_second_ontology.owl')
    with onto1:
        class Drug(Thing):pass
    with onto2:
        class Substance(Thing): pass
    Drug.is_a.append(Substance)
    print('\tDrug.is_a: ', Drug.is_a)

create_class_in_spacific_namespace()
modifying_class_defined_another_ontology()